/**
*   FuzzyEngine - an Simple flex framework 
*   Copyright (C) 2010 Constantin Aldea
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package fuzzy.penelope.helpers {
	import mx.collections.ArrayCollection;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.utils.ObjectUtil;
	
	public class SortModel
	{

			public static function compareNome(valueA:Object, valueB:Object):int{
				
				return 1; 
			} 
			
			public static function compareValid(valueA:Object, valueB:Object):int{

				return 1; 
			}
		
			public static function compareScoperta(valueA:Object, valueB:Object):int{
				
				return 1;
			}
			
			public static function compareNumeric(valueA:Object, valueB:Object):int{
				return ObjectUtil.numericCompare(parseFloat(valueA.scheda.stato), parseFloat(valueA.stato));
			}
			
			public static function compareCurrency(valueA:Object, valueB:Object):int{
				return ObjectUtil.numericCompare(parseFloat(valueA.scheda.totaleSpesa), parseFloat(valueA.scheda.totaleSpesa));
			}
			
			
			public static function compareCause(valueA:Object, valueB:Object):int{
				
				return 1;
			}
			
			public static function compareState(valueA:Object, valueB:Object):int{
				
				return 1; 
			}
			
			public static function compareTipo(valueA:Object, valueB:Object):int{
				
				return 1; 
			}	
			
			public static function compareCode(valueA:Object, valueB:Object):int{
				return ObjectUtil.numericCompare(parseInt(valueA.scheda.id), parseInt(valueB.scheda.id));
			}
			
			public static function compareHours(valueA:Object, valueB:Object):int{
				
				return 1; 
			}
			
			
			public static function sortById(val:ArrayCollection):ArrayCollection{
				if(val != null && val.length > 1){
						var sortById:SortField = new SortField('id', true, true, true);
						var numericSort:Sort = new Sort();
						numericSort.fields = [sortById];
						val.sort = numericSort;
						val.refresh();
					
				}	
				return val;
		}
		
	}
}